package br.edu.sistemaacademico.command;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import java.util.List;

import br.edu.sistemaacademico.builder.*;
import br.edu.sistemaacademico.pojo.*;
public class CommandTurma extends UnicastRemoteObject implements Command, Serializable{
	TurmaDAO turmaDao = new TurmaDAO();
	
	protected CommandTurma() throws RemoteException {
		super();
	}
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public boolean alterar(Object o) throws RemoteException {
		Turma turma = (Turma) o;
		try {
			turmaDao.alterar(turma);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public Object carregaObjeto(String condicao, String tabelasAdd)
			throws RemoteException {
			try {
				return turmaDao.getObject(condicao, tabelasAdd);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
	}

	@Override
	public List<Object> carregar(String condicao, String tabelasAdd)
			throws RemoteException {
		return turmaDao.getAll(condicao, tabelasAdd, "periodo desc");
	}

	@Override
	public boolean deletar(Object o) throws RemoteException {
		Turma turma = (Turma) o;
		try {
			turmaDao.deletar(turma);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public List<Object> getCampos() throws RemoteException {
		return turmaDao.getCampos();
	}

	@Override
	public boolean gravar(Object o) throws RemoteException {
		Turma turma = (Turma) o;
		try {
			turmaDao.gravar(turma);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

}
